<?php
/**
 * 脚本监控 
 */
class Cli_MonitorController extends Ctrl_Cli{
	public function indexAction(){
        $tRunscriptfile = APPLICATION_PATH . '/shell/runscript.ini';
        $tRunscriptlist = Tool_Fnc::readfile($tRunscriptfile);

        $tArrfile = explode("\n",$tRunscriptlist);
        foreach($tArrfile as $tVal){
            if(empty($tVal)){continue;} 
            $this->process($tVal);
        }
        exit();
	}

    private function process($pPs){
        $tTime = time();
        $tRunlogfile = APPLICATION_PATH . '/shell/runlog/'.$pPs.'.run';

        $tRuntime = 0;
        if(is_file($tRunlogfile)){
            $tRuntime = Tool_Fnc::readfile($tRunlogfile); 
        }
        $tM = ($tTime-$tRuntime)/60;
        if($tM < 1){
            return ; 
        }


        system("kill `ps -ef|grep ".$pPs." | grep -v grep|awk '{print $2}'`");
        pclose(popen(Yaf_Registry::get("config")->sys->php->bin.' -f '.APPLICATION_PATH.'/shell/Cli.php request_uri=/'.$pPs.' &','r'));
    }
}
